#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e7;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
string s[40],t1[40];
string ans[maxn];
map<string,LL>map1;
LL num=0;
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL n,m;cin>>n>>m;
   for(LL i=1;i<=n;i++) cin>>s[i];
   for(LL j=1;j<=m;j++) cin>>t1[j];
   LL tot=1;LL cnt=1;
//   while(1){
//      string str=s[tot]+t[cnt];
//      ///cout<<str<<"\n";
//      if(map1.count(str)) break;
//      map1[str]++;
//      ans[++num]=str;
//      tot++;cnt++;
//      if(tot==n+1) tot=1;
//      if(cnt==m+1) cnt=1;
//
//   }
//  ////debug(num);
   LL q;cin>>q;
   while(q--){
      LL t;cin>>t;
      LL mod1=t%n;
      if(mod1==0) mod1=n;
      LL mod2=t%m;
      if(mod2==0) mod2=m;
      cout<<s[mod1]+t1[mod2]<<"\n";

   }
   return 0;
}
